import request from "@/axios/request";
import { defineStore } from "pinia";
import { store } from "./store";

export const useWorkflowDesignStore = defineStore("workflowDesign", () => {
  function health(params) {
    return request.get({
      url: "/api/Health",
      params: params,
    });
  }
  function getAllconditions(params) {
    return request.get({
      url: "/api/workflowDesign/GetAllconditions",
      params: params,
    });
  }
  function getAllUserSelectors(params) {
    return request.get({
      url: "/api/workflowDesign/GetAllUserSelectors",
      params: params,
    });
  }
  function getUserSelectionsOfUserSelector(params) {
    return request.get({
      url: "/api/workflowDesign/GetUserSelectionsOfUserSelector",
      params: params,
    });
  }
  function createWorkFlow(data) {
    return request.post({
      url: "/api/workflowDesign/CreateWorkFlow",
      data: data,
    });
  }
  function createOrUpdateWorkFlow(data) {
    return request.post({
      url: "/api/workflowDesign/CreateOrUpdateWorkFlow",
      data: data,
    });
  }
  function getAllWorkflows(params) {
    return request.get({
      url: "/api/workflowDesign/GetAllWorkflows",
      params: params,
    });
  }
  function getAllWorkflowVersions(params) {
    return request.get({
      url: "/api/workflowDesign/GetAllWorkflowVersions",
      params: params,
    });
  }
  function getWorkflowVersion(params) {
    return request.get({
      url: "/api/workflowDesign/GetWorkflowVersion",
      params: params,
    });
  }
  function getWorkflowVersionByTaskId(params) {
    return request.get({
      url: "/api/workflowDesign/GetWorkflowVersionByTaskId",
      params: params,
    });
  }
  function Delete(params) {
    return request.delete({
      url: "/api/workflowDesign/delete",
      params: params,
    });
  }
  function updateWorkflowActiveVersion(data) {
    return request.put({
      url: "/api/workflowDesign/UpdateWorkflowActiveVersion",
      data: data,
    });
  }
  function updateWorkflow(data) {
    return request.put({
      url: "/api/workflowDesign/UpdateWorkFlow",
      data: data,
    });
  }

  function getAllWorkflowsWithVersion(params) {
    return request.get({
      url: "/api/workflowDesign/GetAllWorkflowsWithVersion",
      params: params,
    });
  }
  function lockWorkflowVersion(params) {
    return request.post({
      url: "/api/workflowDesign/LockWorkflowVersion",
      data: params,
    });
  }
  function lockWorkflow(params) {
    return request.post({
      url: "/api/workflowDesign/LockWorkflow",
      data: params,
    });
  }

  function getAllWorkflowsWithDefaultVersion(params) {
    return request.get({
      url: "/api/workflowDesign/GetAllWorkflowsWithDefaultVersion",
      method: "get",
      params: params,
    });   
  }
  function getUsersOfUserSelecton(params) {
    return request.get({
      url: "/api/workflowDesign/GetUsersOfUserSelecton",
      params: params,
    });
  }
  function getAllWorkflowsWithDefaultVersionGroup(params) {
    return request.get({
      url: "/api/workflowDesign/GetAllWorkflowsWithDefaultVersionGroup",
      method: "get",
      params: params,
    });   
  }

  return {
    getAllconditions,
    getAllUserSelectors,
    createWorkFlow,
    getAllWorkflows,
    getWorkflowVersion,
    getWorkflowVersionByTaskId,
    getAllWorkflowVersions,
    getUsersOfUserSelecton,
    getAllWorkflowsWithVersion,

    lockWorkflowVersion,
    lockWorkflow,
    getUserSelectionsOfUserSelector,
    delete: Delete,
    updateWorkflowActiveVersion,
    updateWorkflow,
    createOrUpdateWorkFlow,
    getAllWorkflowsWithDefaultVersion,
    getAllWorkflowsWithDefaultVersionGroup,
  };
});

export const useWorkflowDesignStoreWithOut = () => {
  return useWorkflowDesignStore(store);
};
